package com.icehand.disruptor.starter.config;

import com.icehand.disruptor.starter.utils.WaitStrategys;
import com.lmax.disruptor.WaitStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;

/**
 * disruptor configuration
 * @author zhoujunmei
 * @date 2019-07-24 11:03
 */
@Slf4j
@EnableConfigurationProperties(value = DisruptorProperties.class)
public class DisruptorConfiguration implements ApplicationContextAware {
    @Autowired
    private DisruptorProperties disruptorProperties;

    private ApplicationContext applicationContext;

    @Bean
    @ConditionalOnMissingBean
    public WaitStrategy waitStrategy(){
        return WaitStrategys.BLOCKING_WAIT;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
